﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MS.INV.MainData
{
    public partial class UnitConversion : Lib.Bases.Forms.BaseForm
    {
        SysObj.Dv_ChuyenDoi cls;

        public UnitConversion()
        {
            InitializeComponent();

            cls = new SysObj.Dv_ChuyenDoi();
        }

        protected override void OnHandleDestroyed(EventArgs e)
        {
            cls.Dispose();
            base.OnHandleDestroyed(e);
        }

        private void UnitConversion_Load(object sender, EventArgs e)
        {
            using (SysLst.L_DVT dvt = new SysLst.L_DVT())
            {
                DataTable DT = dvt.LoadData();
                repHH.SetDataSource(DT, "TenDVT#Tên đơn vị");
                repDV2.SetDataSource(DT.Copy(), "TenDVT#Tên đơn vị");
            }

            grid.DataSource = cls.LoadData();
        }

        private void barUpdate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                cls.Update(grid.GetAcceptChanges());
                barUpdate.Enabled = false;
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "Update data");
            }
        }

        private void view_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            barUpdate.Enabled = true;
        }

        private void barClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }
    }
}
